home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / bin / DXUtils / AppWizard / DXAppwiz.awx / TEMPLATE / GDI_DLG.H < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-25  |  15.5 KB  |  452 lines

  1. // $$root$$.h : main header file for the $$root$$ application
  2. //
  3.  
  4. #if !defined($$FILE_NAME_SYMBOL$$_INCLUDED_)
  5. #define $$FILE_NAME_SYMBOL$$_INCLUDED_
  6.  
  7. #if _MSC_VER > 1000
  8. #pragma once
  9. #endif // _MSC_VER > 1000
  10.  
  11. #ifndef __AFXWIN_H__
  12.     #error include 'stdafx.h' before including this file for PCH
  13. #endif
  14.  
  15. #include "resource.h"       // main symbols
  16.  
  17.  
  18.  
  19. #ifdef _DEBUG
  20. #define new DEBUG_NEW
  21. #undef THIS_FILE
  22. static char THIS_FILE[] = __FILE__;
  23. #endif
  24. $$IF(DPLAY)
  25.  
  26.  
  27.  
  28.  
  29. //-----------------------------------------------------------------------------
  30. // Player context locking defines
  31. //-----------------------------------------------------------------------------
  32. CRITICAL_SECTION g_csPlayerContext;
  33. #define PLAYER_LOCK()                   EnterCriticalSection( &g_csPlayerContext ); 
  34. #define PLAYER_ADDREF( pPlayerInfo )    if( pPlayerInfo ) pPlayerInfo->lRefCount++;
  35. #define PLAYER_RELEASE( pPlayerInfo )   if( pPlayerInfo ) { pPlayerInfo->lRefCount--; if( pPlayerInfo->lRefCount <= 0 ) SAFE_DELETE( pPlayerInfo ); } pPlayerInfo = NULL;
  36. #define PLAYER_UNLOCK()                 LeaveCriticalSection( &g_csPlayerContext );
  37.  
  38. CRITICAL_SECTION g_csWorldStateContext;
  39. #define WORLD_LOCK()                   EnterCriticalSection( &g_csWorldStateContext ); 
  40. #define WORLD_UNLOCK()                 LeaveCriticalSection( &g_csWorldStateContext );
  41. $$ENDIF
  42.  
  43.  
  44.  
  45.  
  46. //-----------------------------------------------------------------------------
  47. // Defines, and constants
  48. //-----------------------------------------------------------------------------
  49. // TODO: change "DirectX AppWizard Apps" to your name or the company name
  50. #define DXAPP_KEY        TEXT("Software\\DirectX AppWizard Apps\\$$root$$")
  51.  
  52. $$IF(ACTIONMAPPER|DPLAY)
  53. // This GUID must be unique for every game, and the same for 
  54. // every instance of this app.  // $$GUIDMSG$$
  55. $$IF(DPLAY)
  56. // The GUID allows DirectPlay to find other instances of the same game on
  57. // the network.  
  58. $$ENDIF // end DPLAY
  59. $$IF(ACTIONMAPPER)
  60. // The GUID allows DirectInput to remember input settings
  61. $$ENDIF // end ACTIONMAPPER
  62. GUID g_guidApp = $$GUIDSTRUCT$$;
  63.  
  64.  
  65. $$ENDIF // end (ACTIONMAPPER|DPLAY)
  66. $$IF(DPLAY)
  67. // Associate a structure with every network player
  68. struct APP_PLAYER_INFO
  69. {
  70.     // TODO: change as needed
  71.     LONG  lRefCount;                        // Ref count so we can cleanup when all threads 
  72.                                             // are done w/ this object
  73.     DPNID dpnidPlayer;                      // DPNID of player
  74.     TCHAR strPlayerName[MAX_PATH];          // Player name
  75.  
  76. $$IF(ACTIONMAPPER)
  77.     FLOAT fAxisRotateUD;                    // State of axis for this player
  78.     FLOAT fAxisRotateLR;                    // State of axis for this player
  79. $$ELSE
  80.     BOOL  bRotateUp;                       // State of up button or this player
  81.     BOOL  bRotateDown;                     // State of down button or this player
  82.     BOOL  bRotateLeft;                     // State of left button or this player
  83.     BOOL  bRotateRight;                    // State of right button or this player
  84. $$ENDIF
  85. $$IF(DPLAYVOICE)
  86.  
  87.     BOOL  bHalfDuplex;                      // TRUE if player is in half-duplex mode
  88.     BOOL  bTalking;                         // TRUE if player is talking
  89. $$ENDIF
  90.  
  91.     APP_PLAYER_INFO* pNext;
  92.     APP_PLAYER_INFO* pPrev;
  93. };
  94.  
  95.  
  96. $$ENDIF // end DPLAY
  97. $$IF(ACTIONMAPPER)
  98. // DirectInput action mapper reports events only when buttons/axis change
  99. // so we need to remember the present state of relevant axis/buttons for 
  100. // each DirectInput device.  The CInputDeviceManager will store a 
  101. // pointer for each device that points to this struct
  102. struct InputDeviceState
  103. {
  104.     // TODO: change as needed
  105.     FLOAT fAxisRotateLR;
  106.     BOOL  bButtonRotateLeft;
  107.     BOOL  bButtonRotateRight;
  108.  
  109.     FLOAT fAxisRotateUD;
  110.     BOOL  bButtonRotateUp;
  111.     BOOL  bButtonRotateDown;
  112. $$IF(DMUSIC || DSOUND)
  113.  
  114.     BOOL  bButtonPlaySoundButtonDown;
  115. $$ENDIF
  116. };
  117.  
  118.  
  119. $$ENDIF
  120. // Struct to store the current input state
  121. struct UserInput
  122. {
  123. $$IF(KEYBOARD)
  124.     BYTE diks[256];   // DirectInput keyboard state buffer 
  125.  
  126. $$ENDIF
  127.     // TODO: change as needed
  128. $$IF(ACTIONMAPPER)
  129.     FLOAT fAxisRotateUD;
  130.     FLOAT fAxisRotateLR;
  131. $$ELSE // start !ACTIONMAPPER --> (KEYBOARD || !DINPUT)
  132.     BOOL bRotateUp;
  133.     BOOL bRotateDown;
  134.     BOOL bRotateLeft;
  135.     BOOL bRotateRight;
  136. $$ENDIF 
  137. $$IF(DMUSIC || DSOUND)
  138.     BOOL bPlaySoundButtonDown;
  139. $$ENDIF
  140. $$IF(ACTIONMAPPER)
  141.     BOOL bDoConfigureInput;
  142. $$ENDIF
  143. $$IF(DPLAYVOICE)
  144.     BOOL bDoConfigureVoice;
  145. $$ENDIF
  146. };
  147.  
  148.  
  149. $$IF(ACTIONMAPPER)
  150. // Input semantics used by this app
  151. enum INPUT_SEMANTICS
  152. {
  153.     // Gameplay semantics
  154.     // TODO: change as needed
  155.     INPUT_ROTATE_AXIS_LR=1, INPUT_ROTATE_AXIS_UD,       
  156.     INPUT_ROTATE_LEFT,      INPUT_ROTATE_RIGHT,    
  157.     INPUT_ROTATE_UP,        INPUT_ROTATE_DOWN,
  158.     INPUT_CONFIG_INPUT,     
  159. $$IF(DPLAYVOICE)
  160.     INPUT_CONFIG_VOICE,     
  161. $$ENDIF
  162. $$IF(DMUSIC || DSOUND)
  163.     INPUT_PLAY_SOUND,       
  164. $$ENDIF
  165. };
  166.  
  167. // Actions used by this app
  168. DIACTION g_rgGameAction[] =
  169. {
  170.     // TODO: change as needed.  Be sure to delete user map files 
  171.     // (C:\Program Files\DirectX\DirectInput\User Maps\*.ini)
  172.     // after changing this, otherwise settings won't reset and will be read 
  173.     // from the out of date ini files 
  174.  
  175.     // Device input (joystick, etc.) that is pre-defined by DInput, according
  176.     // to genre type. The genre for this app is space simulators.
  177.     { INPUT_ROTATE_AXIS_LR,  DIAXIS_3DCONTROL_LATERAL,      0, TEXT("Rotate left/right"), },
  178.     { INPUT_ROTATE_AXIS_UD,  DIAXIS_3DCONTROL_MOVE,         0, TEXT("Rotate up/down"), },
  179. $$IF(DMUSIC || DSOUND)
  180.     { INPUT_PLAY_SOUND,      DIBUTTON_3DCONTROL_SPECIAL,    0, TEXT("Play sound"), },
  181. $$ENDIF
  182.  
  183.     // Keyboard input mappings
  184.     { INPUT_ROTATE_LEFT,     DIKEYBOARD_LEFT,               0, TEXT("Rotate left"), },
  185.     { INPUT_ROTATE_RIGHT,    DIKEYBOARD_RIGHT,              0, TEXT("Rotate right"), },
  186.     { INPUT_ROTATE_UP,       DIKEYBOARD_UP,                 0, TEXT("Rotate up"), },
  187.     { INPUT_ROTATE_DOWN,     DIKEYBOARD_DOWN,               0, TEXT("Rotate down"), },
  188. $$IF(DMUSIC || DSOUND)
  189.     { INPUT_PLAY_SOUND,      DIKEYBOARD_F5,                 0, TEXT("Play sound"), },
  190. $$ENDIF
  191.     { INPUT_CONFIG_INPUT,    DIKEYBOARD_F3,                 DIA_APPFIXED, TEXT("Configure Input"), },    
  192. $$IF(DPLAYVOICE)
  193.     { INPUT_CONFIG_VOICE,    DIKEYBOARD_F4,                 DIA_APPFIXED, TEXT("Configure Voice"), },    
  194. $$ENDIF
  195. };
  196.  
  197. #define NUMBER_OF_GAMEACTIONS    (sizeof(g_rgGameAction)/sizeof(DIACTION))
  198.  
  199.  
  200. $$ENDIF
  201. $$IF(DPLAY)
  202. //-----------------------------------------------------------------------------
  203. // App specific DirectPlay messages and structures 
  204. //-----------------------------------------------------------------------------
  205.  
  206. // TODO: change or add app specific DirectPlay messages and structures as needed
  207. #define GAME_MSGID_WORLDSTATE    1
  208. #define GAME_MSGID_INPUTSTATE    2
  209. #define GAME_MSGID_HOSTPAUSE     3
  210.  
  211. // Change compiler pack alignment to be BYTE aligned, and pop the current value
  212. #pragma pack( push, 1 )
  213.  
  214. struct GAMEMSG_GENERIC
  215. {
  216.     // One of GAME_MSGID_* IDs so the app knows which GAMEMSG_* struct
  217.     // to cast the msg pointer into.
  218.     WORD nType; 
  219. };
  220.  
  221. struct GAMEMSG_WORLDSTATE : public GAMEMSG_GENERIC
  222. {
  223.     FLOAT fWorldRotX;
  224.     FLOAT fWorldRotY;
  225. };
  226.  
  227. struct GAMEMSG_INPUTSTATE : public GAMEMSG_GENERIC
  228. {
  229. $$IF(ACTIONMAPPER)
  230.     FLOAT fAxisRotateUD;
  231.     FLOAT fAxisRotateLR;
  232. $$ELSE
  233.     BOOL  bRotateUp;   
  234.     BOOL  bRotateDown; 
  235.     BOOL  bRotateLeft; 
  236.     BOOL  bRotateRight;
  237. $$ENDIF
  238. };
  239.  
  240. struct GAMEMSG_HOSTPAUSE : public GAMEMSG_GENERIC
  241. {
  242.     BOOL bHostPause;
  243. };
  244.  
  245. // Pop the old pack alignment
  246. #pragma pack( pop )
  247.  
  248.  
  249. $$ENDIF
  250.  
  251.  
  252. //-----------------------------------------------------------------------------
  253. // Name: class C$$CRoot$$Dlg
  254. // Desc: Dialog class derived from CDialog
  255. //-----------------------------------------------------------------------------
  256. class C$$CRoot$$Dlg : public CDialog
  257. {
  258. public:
  259.     C$$CRoot$$Dlg(CWnd* pParent = NULL);    // standard constructor
  260.  
  261.     FLOAT                   m_fTime;                // Current time in seconds
  262.     FLOAT                   m_fElapsedTime;         // Time elapsed since last frame
  263.  
  264. protected:
  265.     BOOL                    m_bLoadingApp;          // TRUE, if the app is loading
  266.     BOOL                      m_bHasFocus;        // TRUE, if the app has focus
  267.     TCHAR*                  m_strWindowTitle;       // Title for the app's window
  268.     DWORD                   m_dwCreationWidth;      // Width used to create window
  269.     DWORD                   m_dwCreationHeight;     // Height used to create window
  270.  
  271. $$IF(KEYBOARD)
  272.     LPDIRECTINPUT8          m_pDI;                  // DirectInput object
  273.     LPDIRECTINPUTDEVICE8    m_pKeyboard;            // DirectInput keyboard device
  274. $$ENDIF
  275. $$IF(ACTIONMAPPER)
  276.     CInputDeviceManager*    m_pInputDeviceManager;  // DirectInput device manager
  277.     DIACTIONFORMAT          m_diafGame;             // Action format for game play
  278. $$ENDIF
  279.     UserInput               m_UserInput;            // Struct for storing user input 
  280.  
  281. $$IF(DMUSIC || DSOUND)
  282.     FLOAT                   m_fSoundPlayRepeatCountdown; // Sound repeat timer
  283. $$IF(DMUSIC)
  284.     CMusicManager*          m_pMusicManager;        // DirectMusic manager class
  285.     CMusicSegment*          m_pBounceSound;         // Bounce sound
  286. $$ELSE // start !DMUSIC
  287.     CSoundManager*          m_pSoundManager;        // DirectSound manager class
  288.     CSound*                 m_pBounceSound;         // Bounce sound
  289. $$ENDIF // end DMUSIC
  290.  
  291. $$ENDIF // end (DMUSIC || DSOUND)
  292. $$IF(DPLAY)
  293.     IDirectPlay8Peer*       m_pDP;                  // DirectPlay peer object
  294.     CNetConnectWizard*      m_pNetConnectWizard;    // Connection wizard
  295.     IDirectPlay8LobbiedApplication* m_pLobbiedApp;  // DirectPlay lobbied app 
  296.     BOOL                    m_bWasLobbyLaunched;    // TRUE if lobby launched
  297.     DPNID                   m_dpnidLocalPlayer;     // DPNID of local player
  298.     LONG                    m_lNumberOfActivePlayers;        // Number of players currently in game
  299.     TCHAR                   m_strLocalPlayerName[MAX_PATH];  // Local player name
  300.     TCHAR                   m_strSessionName[MAX_PATH];      // Session name
  301.     TCHAR                   m_strPreferredProvider[MAX_PATH];// Provider string
  302.     APP_PLAYER_INFO         m_PlayInfoList;         // List of players
  303.     APP_PLAYER_INFO*        m_pLocalPlayerInfo;     // APP_PLAYER_INFO struct for local player
  304.     HRESULT                 m_hrNet;                // HRESULT of DirectPlay events
  305.     FLOAT                   m_fWorldSyncTimer;      // Timer for syncing world state between players
  306.     BOOL                    m_bHostPausing;         // Has the host paused the app?
  307.     UserInput               m_CombinedNetworkInput; // Combined input from all network players
  308.  
  309. $$ENDIF
  310. $$IF(DPLAYVOICE)
  311.     CNetVoice*              m_pNetVoice;            // DirectPlay voice helper class
  312.     DVCLIENTCONFIG          m_dvClientConfig;       // Voice client config
  313.     GUID                    m_guidDVSessionCT;      // GUID for chosen voice compression
  314.     BOOL                    m_bNetworkPlayersTalking; // TRUE if any of the network players are talking
  315.     BOOL                    m_bLocalPlayerTalking;  // TRUE if the local player is talking
  316.  
  317. $$ENDIF
  318.     FLOAT                   m_fWorldRotX;           // World rotation state X-axis
  319.     FLOAT                   m_fWorldRotY;           // World rotation state Y-axis
  320.  
  321. // Dialog Data
  322.     //{{AFX_DATA(C$$CRoot$$Dlg)
  323.     enum { IDD = IDD_$$SAFE_ROOT$$_DIALOG };
  324.         // NOTE: the ClassWizard will add data members here
  325.     //}}AFX_DATA
  326.  
  327. public:
  328.     HRESULT OneTimeSceneInit();
  329.     HRESULT Render();
  330.     HRESULT FrameMove();
  331.     HRESULT FinalCleanup();
  332.     VOID    Pause( BOOL bPause );
  333.  
  334. protected:
  335.     HRESULT RenderText();
  336.  
  337. $$IF(DINPUT)
  338.     HRESULT InitInput( HWND hWnd );
  339. $$ENDIF // end DINPUT
  340.     void    UpdateInput( UserInput* pUserInput );
  341. $$IF(DPLAY)
  342.     HRESULT CombineInputFromAllPlayers( UserInput* pCombinedUserInput );
  343. $$ENDIF // end DPLAY
  344. $$IF(DINPUT)
  345.     void    CleanupDirectInput();
  346. $$ENDIF // end DINPUT
  347.  
  348. $$IF(DMUSIC || DSOUND)
  349.     HRESULT InitAudio( HWND hWnd );
  350.  
  351. $$ENDIF
  352. $$IF(DPLAY)
  353.     HRESULT InitDirectPlay();
  354.     void    CleanupDirectPlay();
  355.     HRESULT ConnectViaDirectPlay();
  356.     HRESULT SendLocalInputIfChanged();
  357.     HRESULT SendWorldStateToAll();
  358.     HRESULT SendPauseMessageToAll( BOOL bPause );
  359.  
  360. $$ENDIF
  361. $$IF(DPLAYVOICE)
  362.     HRESULT InitDirectPlayVoice();
  363.     VOID    UpdateTalkingVariables();
  364.     HRESULT UserConfigVoice();
  365.  
  366. $$ENDIF
  367.     VOID    ReadSettings();
  368.     VOID    WriteSettings();
  369.  
  370.     // ClassWizard generated virtual function overrides
  371.     //{{AFX_VIRTUAL(C$$CRoot$$Dlg)
  372.     public:
  373.     protected:
  374.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  375.     virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
  376.     //}}AFX_VIRTUAL
  377.  
  378. // Implementation
  379. protected:
  380.     HICON m_hIcon;
  381.  
  382.     // Generated message map functions
  383.     //{{AFX_MSG(C$$CRoot$$Dlg)
  384.     virtual BOOL OnInitDialog();
  385.     //}}AFX_MSG
  386.     DECLARE_MESSAGE_MAP()
  387.  
  388. public:
  389. $$IF(ACTIONMAPPER)
  390.  
  391.     HRESULT InputAddDeviceCB( CInputDeviceManager::DeviceInfo* pDeviceInfo, const DIDEVICEINSTANCE* pdidi );
  392.     static HRESULT CALLBACK StaticInputAddDeviceCB( CInputDeviceManager::DeviceInfo* pDeviceInfo, const DIDEVICEINSTANCE* pdidi, LPVOID pParam );   
  393. $$ENDIF
  394. $$IF(DPLAY)
  395.  
  396.     static HRESULT WINAPI StaticDirectPlayMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  397.     HRESULT DirectPlayMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  398.     static HRESULT WINAPI StaticDirectPlayLobbyMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  399.     HRESULT DirectPlayLobbyMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  400. $$ENDIF
  401. $$IF(DPLAYVOICE)
  402.  
  403.     static HRESULT WINAPI StaticDirectPlayVoiceServerMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  404.     HRESULT DirectPlayVoiceServerMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  405.     static HRESULT WINAPI StaticDirectPlayVoiceClientMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  406.     HRESULT DirectPlayVoiceClientMessageHandler( PVOID pvUserContext, DWORD dwMessageId, PVOID pMsgBuffer );
  407. $$ENDIF
  408. };
  409.  
  410.  
  411.  
  412.  
  413. //-----------------------------------------------------------------------------
  414. // Name: class CApp
  415. // Desc: Main MFC application class derived from CWinApp.
  416. //-----------------------------------------------------------------------------
  417. class C$$CRoot$$App : public CWinApp
  418. {
  419. public:
  420.     C$$CRoot$$App();
  421.  
  422.     C$$CRoot$$Dlg* m_pDlg;
  423.  
  424. // Overrides
  425.     // ClassWizard generated virtual function overrides
  426.     //{{AFX_VIRTUAL(C$$CRoot$$App)
  427.     public:
  428.     virtual BOOL InitInstance();
  429.     virtual BOOL OnIdle(LONG lCount);
  430.     virtual int ExitInstance();
  431.     //}}AFX_VIRTUAL
  432.  
  433. // Implementation
  434.  
  435.     //{{AFX_MSG(C$$CRoot$$App)
  436.         // NOTE - the ClassWizard will add and remove member functions here.
  437.         //    DO NOT EDIT what you see in these blocks of generated code !
  438.     //}}AFX_MSG
  439.     DECLARE_MESSAGE_MAP()
  440. };
  441.  
  442.  
  443.  
  444. /////////////////////////////////////////////////////////////////////////////
  445.  
  446. //{{AFX_INSERT_LOCATION}}
  447. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  448.  
  449. #endif // !defined($$FILE_NAME_SYMBOL$$_INCLUDED_)
  450.  
  451.  
  452.